/**
 * Copyright By Nanjing Fujitsu Nanda Software Technology Co., Ltd
 * 上午10:16:56
 * CoreUserDao.java
 * 
 */
package com.fujitsu.nanjing.mobile.dao;

import com.fujitsu.nanjing.mobile.exception.NotOneException;
import com.fujitsu.nanjing.mobile.model.hibernate.CoreUser;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author qixb.fnst
 * 
 */
@Repository
public class CoreUserDao extends BaseDao<CoreUser> {

    /**
     * qixib.fnst
     * 
     * @param company
     * @param username
     * @param password
     * @return
     */
    public CoreUser checkUser(String company, String username, String password) {
        Session session = getSession();
        Criteria criteria = session.createCriteria(CoreUser.class);
        criteria.add(Restrictions.eq("username", username))
                .add(Restrictions.eq("password", password))
                .add(Restrictions.eq("companyName", company));
        try {
            CoreUser user = query4One(criteria);
            return user;
        } catch (NotOneException e) {
            e.printStackTrace();
            return null;
        } finally {
            releaseSession(session);
        }

    }

    /**
     * qixib.fnst
     * @param whereClause
     * @return
     */
    public int getUserNums(String whereClause) {

        return queryNums(CoreUser.class, whereClause);
    }

    /**
     * qixib.fnst
     * @param orderClause
     * @param whereClause
     * @param userLimit
     * @param firstRecord
     * @param limit
     * @return
     */
    public List<CoreUser> getUsers(String orderClause, String whereClause,
            boolean userLimit, int firstRecord, int limit) {
        return query4Page(CoreUser.class, orderClause, whereClause, userLimit, firstRecord, limit);
    }

}
